define(function(require, exports, module){
	myApp  = seajs.data.vars.myApp;
	$$  = seajs.data.vars.dom;
	mainview = seajs.data.vars.mainview;
	function page(){
		var _basePage=this;
		this.init=function(){
			
			//获取客户id
			var id = $$('#id').val();
			var url = "/m/customer/customerinfo";
			 
			//人才详细信息
			 resumeobj = new Vue({
				el:'#resumeinfo',
				data:{info:{},param:{}},
				created:function(){
					var _self=this;
					$$.ajax({
						url:url,
						method:"POST",
						async:false,
						data:{id:id},
						success:function(data){
							if(data!=null){
								_self.info = eval("(" + data +")");
							}
						}
					});
				},
				mounted:function(){},
				beforeUpdate:function(){},
				updated:function(){},
				methods: {
					//重新获取数据
					reloaddata: function(id){
						
					}
				},
			}); 
			 
			 
			 //点击进入修改对应条目页面
			 $$(document).on("click",".iteminfo",function(){
				 //根据id展示对应页面
				 var id = $$(this).attr("data");
				 var namedata = $$(this).attr("namedata");
				 //加载页面
				 mainview.router.loadContent($$("#"+id).html());
				 //在基本的input框中,不一样的只有QQ和微信
				 if (namedata == 'qq') {
					 $$(".resumeqq").eq(1).val(resumeobj.info.contactsItem[0].qq);
				 } else if (namedata == 'webchart') {
					 $$(".resumewebchart").eq(1).val(resumeobj.info.contactsItem[0].webchart);
				 } else {
					 for (var prop in resumeobj.info) {
						 if (prop == namedata) {
							//成熟等级(state),客户来源(source),客户分类(level)是选择
							 if (namedata === 'state' || namedata === 'source' || namedata === 'level') {
								 $$("input[name='"+ namedata +"']").each(function(){
									 $$("input[value='"+ resumeobj.info[prop] + "']").attr("checked",true);
								 });
								 break;
							 } else {
								 $$(".resume"+prop).eq(1).val(resumeobj.info[prop]);
								 break;
							 }
						 }
					 }
				 }
			 });
			 
			 //点击保存修改
			 $$(".itemsave").on("touchend",function(){
				 
				 //点击保存:qq和微信要通过customerinfo带到后台
				 
				 var qq = resumeobj.info.contactsItem[0].qq;
				 var webchart = resumeobj.info.contactsItem[0].webchart;
				 
				 
				 resumeobj.info.qq = qq;
				 resumeobj.info.webchart = webchart;
				 
				 /*//获取字段
				 var namedata = $$(this).attr("namedata");
				 //获取值
				 var value;
				 
				 if (namedata === 'state' || namedata === 'source' || namedata === 'level') {
					 value = $$("input[name='"+ namedata +"']:checked").eq(1).val();
				 } else {
					 value = $$(".resume"+namedata).eq(1).val();
				 }
				 alert(1)
				 for (var prop in resumeobj.info) {
					 if (prop == namedata) {
						 alert(prop+"---"+namedata);
						 alert("未改变前的值:"+resumeobj.info[prop]);
						 resumeobj.info[prop] = value;
						 alert("改变后的值:"+resumeobj.info[prop]);
						 break;
					 }
				 }*/
				 
				 //把resumeobj.info中的信息拷贝到一个新的对象中
				 var paramdata = JSON.parse(JSON.stringify(resumeobj.info));
				 //删除对象中不需要的key
				 delete paramdata["contactsItem"];
				 //然后就是保存
				 $$.ajax({
					 type : "post",
					 url : "/m/customer/updatecustomer",
					 data : paramdata,
					 dataType : "json",
					 async:false,
					 success : function(data){
						 myApp.toast().show("更新成功");
						 //window.location.href = "/m/customer/updatecustomer"+id;
					 }
				 });
				 //var tel = $$(".resumetel").eq(1).val();
				 //var state = $$("input[name='state']:checked").eq(1).val();
				 
			 });
			
		}
	}
	 module.exports=new page();
})